package main

import (
	"bytes"
	"encoding/gob"
	"fmt"
	"log"
)

type Base struct {
	Name string `json:"name"`
	Map map[string]string `json:"map"`
}

type Person struct {
	base *Base `json:"base"`
	Age string `json:"age"`
}



func main() {
	obj1 := NewPerson()
	obj2 := NewPerson()
	//fmt.Println(obj)
	fmt.Println(obj1)
	fmt.Println(obj2)

	GobData1 := obj1.SerializeGob()
	GobData2 := obj2.SerializeGob()
	fmt.Println(GobData1)
	fmt.Println(GobData2)


	//fmt.Println(obj1.base.Map["hello"])
}

func NewPerson() *Person {
	test := make(map[string]string)
	test["hello"] = "world"

	baseObj := &Base{
		Name: "yangyi",
		Map: test,
	}

	return &Person{
		base: baseObj,
		Age: "18",
	}
}


func(per *Person) SerializeGob() []byte{
	// 编码的数据放到buffer中
	var buffer bytes.Buffer

	// 使用gob进行序列化(编码)得到字节流
	// 1 定义一个编码器
	// 2 使用编码器进行编码
	encoder := gob.NewEncoder(&buffer)
	err := encoder.Encode(per)
	if err != nil {
		log.Panic("账户树编码出错...")
	}

	return buffer.Bytes()

	return nil
}


func(per *Person) SerializeJson() []byte {
	return nil
}


func DeserializeGob() *Person {
	return nil
}

func DeserializeJson() *Person {
	return nil
}
